package com.cloudspace.yunloan.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudspace.yunloan.R;
import com.cloudspace.yunloan.YunloanApp;
import com.cloudspace.yunloan.entity.CaseEntity;
import com.cloudspace.yunloan.utils.ObjUtil;

import java.util.List;

public class UnFinishCaseAdapter extends BaseAdapter {
    private List<CaseEntity> unFinishCaseEntities;

    public void setData(List<CaseEntity> entities){
        this.unFinishCaseEntities = entities;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (ObjUtil.isEmpty(unFinishCaseEntities))
            return 1;

        return unFinishCaseEntities.size()+1;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(YunloanApp.getInstance()).inflate(R.layout.layout_item_case_unfinish, null);

            holder = new ViewHolder();
            holder.nameTv = (TextView) convertView.findViewById(R.id.name);
            holder.idCardTv = (TextView) convertView.findViewById(R.id.idcard);
            holder.opTimeTv = (TextView) convertView.findViewById(R.id.opTime);
            holder.stepTv = (TextView) convertView.findViewById(R.id.step);

            holder.contentView = convertView.findViewById(R.id.contentRl);
            holder.addView = convertView.findViewById(R.id.add_rl);

            convertView.setTag(holder);
        }

        holder = (ViewHolder) convertView.getTag();

        if (position == 0){
            holder.contentView.setVisibility(View.GONE);
            holder.addView.setVisibility(View.VISIBLE);
        }else{
            int index = position - 1;

            holder.contentView.setVisibility(View.VISIBLE);
            holder.addView.setVisibility(View.GONE);

            String name = unFinishCaseEntities.get(index).name;
            holder.nameTv.setText(name);
            holder.idCardTv.setText(unFinishCaseEntities.get(index).idCard);
            if (unFinishCaseEntities.get(index).state == 1){
                holder.stepTv.setText("第一步>>");
            }else{
                holder.stepTv.setText("第二步>>");
            }
            holder.opTimeTv.setText("操作时间：" + unFinishCaseEntities.get(index).time);
        }

        return convertView;
    }

    static class ViewHolder{
        TextView nameTv;
        TextView idCardTv;
        TextView opTimeTv;
        TextView stepTv;

        View contentView;
        View addView;
    }
}
